home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60750 / 60750.xpi / chrome / chromeFiles / content / bindings / btbutton.xml < prev    next >
Extensible Markup Language  |  2010-01-20  |  12KB  |  270 lines

  1. <?xml version="1.0"?>
  2. <bindings id="btbuttonBindings"
  3.       xmlns="http://www.mozilla.org/xbl"
  4.       xmlns:html="http://www.w3.org/1999/xhtml"
  5.       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.       xmlns:xbl="http://www.mozilla.org/xbl">
  7.  
  8.   <binding id="btbutton" extends="xul:box">
  9.     <content>
  10.     <xul:button id="bt-button-brandthunder" class="bt_brandthunder_btn"
  11.             type="menu">
  12.       <xul:menupopup anonid="btbutton-bt-popup">
  13.         <xul:menuitem anonid="btbutton-tutorial-menu" label="Tutorial"/>
  14.         <xul:menuitem anonid="btbutton-faqs-menu" label="FAQS"/>
  15.         <xul:menuitem anonid="btbutton-help-menu" label="Help"/>
  16.         <xul:menuseparator/>
  17.         <xul:menuitem class="menuitem-iconic" anonid="btbutton-sharethis-menu" label="Share This"/>
  18.         <xul:menuseparator/>
  19.         <xul:menu anonid="btbutton-boomswitch-menu" label="Boom your browser!">
  20.           <xul:menupopup anonid="btbutton-boomswitch-popup">
  21.           </xul:menupopup>
  22.         </xul:menu>
  23.         <xul:menuitem anonid="btbutton-boomtype-menu" label="Display Toolbar Only"/>
  24.         <xul:menuseparator/>
  25.         <xul:menuitem anonid="btbutton-uninstall-menu" label="Uninstall"/>
  26.         <xul:menuseparator/>
  27.         <xul:menuitem anonid="btbutton-brandthunder-menu" label="Brand Thunder"/>
  28.       </xul:menupopup>
  29.     </xul:button>
  30.  
  31.     </content>
  32.     <handlers>
  33.       <handler event="command">
  34.         <![CDATA[
  35.         switch (event.originalTarget.getAttribute("anonid")) {
  36.           case "btbutton-tutorial-menu":
  37.           case "btbutton-sharethis-menu":
  38.           case "btbutton-help-menu":
  39.           case "btbutton-faqs-menu":
  40.           case "btbutton-brandthunder-menu":
  41.           case "btbutton-morebooms-menu":
  42.             this.brandObject.utilities.openLink(this.brandObject, event, event.originalTarget.getAttribute("url"));
  43.             break;
  44.           case "btbutton-uninstall-menu":
  45.             this.brandObject.utilities.uninstall(this.brandObject, this.btClientBundle);
  46.             break;
  47.           case "btbutton-boomtype-menu":
  48.             this.toolbarMenuCommand(event);
  49.             break;
  50.         }
  51.         if (event.originalTarget.hasAttribute("boom")) {
  52.           this.btPrefBranch.setCharPref("currentBoom", event.originalTarget.getAttribute("boom"));
  53.           var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  54.                                   .getService(Components.interfaces.nsIPrefBranch);
  55.           var dynamicBoom = false;
  56.           try {
  57.             dynamicBoom = this.btPrefBranch.getBoolPref("dynamicBoom");
  58.           } catch (ex) {}
  59.           if (!dynamicBoom) {
  60.             if (prefbranch.getCharPref("general.skins.selectedSkin") != "classic/1.0") {
  61.               this.switchRestart();
  62.             }
  63.           }
  64.         }
  65.         ]]>
  66.       </handler>
  67.       <handler event="popupshowing">
  68.         <![CDATA[
  69.         switch (event.originalTarget.getAttribute("anonid")) {
  70.           case "btbutton-bt-popup":
  71.             var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-boomtype-menu");
  72.             var full = true;
  73.             try {
  74.               full = this.btPrefBranch.getBoolPref("bigBoom");
  75.             } catch (ex) {}
  76.             var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  77.                                      .getService(Components.interfaces.nsIPrefBranch);
  78.  
  79.             var dynamicBoom = false;
  80.             try {
  81.               dynamicBoom = this.btPrefBranch.getBoolPref("dynamicBoom");
  82.             } catch (ex) {}
  83.  
  84.             if (!full || (!dynamicBoom && prefbranch.getCharPref("general.skins.selectedSkin") != "classic/1.0")) {
  85.               menu.setAttribute("label", this.getString("bt-bigboom.label"));
  86.             } else {
  87.               menu.setAttribute("label", this.getString("bt-smallboom.label"));
  88.             }
  89.             
  90.             /* If the current boom has NO buttons, don't allow a switch to small boom */
  91.             if (this.smallBoom == false) {
  92.               menu.hidden = true;
  93.             }
  94.             break;
  95.           case "btbutton-boomswitch-popup":
  96.             for (let i= event.originalTarget.childNodes.length - 1; i >= 0; i--) {
  97.                 event.originalTarget.removeChild(event.originalTarget.childNodes.item(i));
  98.             }
  99.             var currentBoom = this.btPrefBranch.getCharPref("currentBoom");
  100.             for (let i in BrandThunder.clients) {
  101.               var boomLength = 0;
  102.               for (let j in BrandThunder.clients[i].booms) {
  103.                 boomLength++;
  104.               }
  105.               if (boomLength > 1) {
  106.                 var menu = document.createElement("menu");
  107.                 menu.setAttribute("label", BrandThunder.clients[i].clientName);
  108.                 var menupopup = document.createElement("menupopup");
  109.                 menu.appendChild(menupopup);
  110.                 for (let j in BrandThunder.clients[i].booms) {
  111.                   var menuitem = document.createElement("menuitem");
  112.                   menuitem.setAttribute("label", BrandThunder.clients[i].booms[j]);
  113.                   menuitem.setAttribute("boom", j);
  114.                   if (j == currentBoom) {
  115.                     menuitem.setAttribute("type", "checkbox");
  116.                     menuitem.setAttribute("checked", "true");
  117.                   }
  118.                   menupopup.appendChild(menuitem);
  119.                 }
  120.                 event.originalTarget.appendChild(menu);
  121.               } else {
  122.                 for (let j in BrandThunder.clients[i].booms) {
  123.                   var menuitem = document.createElement("menuitem");
  124.                   menuitem.setAttribute("label", BrandThunder.clients[i].booms[j]);
  125.                   menuitem.setAttribute("boom", j);
  126.                   if (j == currentBoom) {
  127.                     menuitem.setAttribute("type", "checkbox");
  128.                     menuitem.setAttribute("checked", "true");
  129.                   }
  130.                   event.originalTarget.appendChild(menuitem);
  131.                 }
  132.               }
  133.             }
  134.             var menusep = document.createElement("menuseparator");
  135.             event.originalTarget.appendChild(menusep);
  136.             var menuitem = document.createElement("menuitem");
  137.             menuitem.setAttribute("anonid", "btbutton-morebooms-menu")
  138.             menuitem.setAttribute("url", this.getString("bt-morebooms.url"));
  139.             menuitem.setAttribute("label", this.getString("bt-morebooms.label"));
  140.             event.originalTarget.appendChild(menuitem);
  141.             break;
  142.         }
  143.         ]]>
  144.       </handler>
  145.     </handlers>
  146.     <implementation>
  147.       <constructor>
  148.         <![CDATA[
  149.         if (this.hasAttribute('btBoomBundle')) {
  150.           this.btBoomBundle = document.getElementById(this.getAttribute('btBoomBundle'));
  151.         }
  152.         if (this.hasAttribute('btClientBundle')) {
  153.           this.btClientBundle = document.getElementById(this.getAttribute('btClientBundle'));
  154.         }
  155.         if (this.hasAttribute('brand')) {
  156.           this.brandObject = BrandThunder.clients[this.getAttribute('brand')];
  157.         }
  158.         if (this.hasAttribute('smallBoom')) {
  159.           var smallBoom = this.getAttribute("smallBoom");
  160.           if (smallBoom == "false") {
  161.             this.smallBoom = false;
  162.           }
  163.         }
  164.         
  165.         if (this.brandObject) {
  166.           this.btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  167.                                         .getService(Components.interfaces.nsIPrefService)
  168.                                         .getBranch("extensions.brandthunder.");
  169.         }
  170.  
  171.          document.getAnonymousElementByAttribute(this, 'anonid', 'btbutton-sharethis-menu')
  172.                  .setAttribute("image", "chrome://" + this.brandObject.packageName +
  173.                                "/content/bindings/resources/btbutton/sharethis.png");
  174.  
  175.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-tutorial-menu");
  176.         menu.setAttribute("url", this.getString("bt-tutorial.url"));
  177.         menu.setAttribute("label", this.getString("bt-tutorial.label"));
  178.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-faqs-menu");
  179.         menu.setAttribute("url", this.getString("bt-faqs.url"));
  180.         menu.setAttribute("label", this.getString("bt-faqs.label"));
  181.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-sharethis-menu");
  182.         menu.setAttribute("url", this.getString("bt-sharethis.url"));
  183.         menu.setAttribute("label", this.getString("bt-sharethis.label"));
  184.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-help-menu");
  185.         menu.setAttribute("url", this.getString("bt-help.url"));
  186.         menu.setAttribute("label", this.getString("bt-help.label"));
  187.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-uninstall-menu");
  188.         menu.setAttribute("label", this.getString("bt-uninstall.label"));
  189.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-boomswitch-menu");
  190.         menu.setAttribute("label", this.getString("bt-boomswitch.label"));
  191.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-boomtype-menu");
  192.         menu.setAttribute("label", this.getString("bt-toolbar.label"));
  193.         var menu = getAnonymousElementByAttribute(this, "anonid", "btbutton-brandthunder-menu");
  194.         menu.setAttribute("url", this.getString("bt-brandthunder.url"));
  195.         menu.setAttribute("label", this.getString("bt-brandthunder.label"));
  196.         ]]>
  197.       </constructor>
  198.       <destructor>
  199.       </destructor>
  200.       <field name="btPrefBranch"/>
  201.       <field name="brandObject"/>
  202.       <field name="btClientBundle"/>
  203.       <field name="btBoomBundle"/>
  204.       <field name="smallBoom">
  205.         true
  206.       </field>
  207.       <method name="switchRestart">
  208.         <body>
  209.           var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  210.                                        .getService(Components.interfaces.nsIPromptService);
  211.           var button = promptService.confirmEx(window, this.btClientBundle.getString("clientName"), this.btClientBundle.getString("switch.confirm"),
  212.                                                (promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
  213.                                                (promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
  214.                                                null, null, null, null, {});
  215.           if (button == 0) {
  216.             this.btPrefBranch.setBoolPref("bigBoom", true);
  217.             this.brandObject.utilities.restartApp();
  218.           }
  219.         </body>
  220.       </method>
  221.       <method name="toolbarMenuCommand">
  222.         <parameter name="event"/>
  223.         <body>
  224.           <![CDATA[
  225.           var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  226.                                   .getService(Components.interfaces.nsIPrefBranch);
  227.           var dynamicBoom = false;
  228.           try {
  229.             dynamicBoom = this.btPrefBranch.getBoolPref("dynamicBoom");
  230.           } catch (ex) {}
  231.           if (!dynamicBoom) {
  232.             if (prefbranch.getCharPref("general.skins.selectedSkin") != "classic/1.0") {
  233.               this.switchRestart();
  234.               return;
  235.             }
  236.           }
  237.  
  238.           var bigBoom = true;
  239.           try {
  240.             bigBoom = this.btPrefBranch.getBoolPref("bigBoom");
  241.           } catch (ex) {}
  242.           this.btPrefBranch.setBoolPref("bigBoom", !bigBoom);
  243.           ]]>
  244.         </body>
  245.       </method>
  246.       <method name="getString">
  247.         <parameter name="id"/>
  248.         <body>
  249.           <![CDATA[
  250.           var string;
  251.           if (this.btBoomBundle) {
  252.             try {
  253.               string = this.btBoomBundle.getString(id);
  254.             } catch(ex) {
  255.             }
  256.           }
  257.           if (!string) {
  258.             try {
  259.               string = this.btClientBundle.getString(id);
  260.             } catch(ex) {
  261.             }
  262.           }
  263.           return string;
  264.           ]]>
  265.         </body>
  266.       </method>
  267.     </implementation>
  268.   </binding>
  269. </bindings>
  270.